<?
$sub_menu = "400200";
include_once("./_common.php");
auth_check($auth[$sub_menu], "r");
$g4[title] = "카테고리 관리";
include_once("./admin.head.php");

$colspan="5";

$QUERY = "SELECT *
						FROM " . $g4['category_table'] . "
							WHERE c_depth='0'
								ORDER BY c_sort ASC,
								c_regday ASC";

$RESULT = mysql_query($QUERY);
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<form name="searchStr" method="post" action="<?=$PHP_SELF?>">
	<tr>
		<td align="right"><input type="text" name="searchCate" class="ed" value="<?=$searchCate?>" style="width:120px"><button class="btn1" onclick="submit();">찾기</button></td>
	</tr>
</form>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
		<colgroup width=50>
		<colgroup width=120>
		<colgroup width=>
		<colgroup width=100>
		<colgroup width=100>
	<tr><td colspan="<?=$colspan?>" class="line1"></td></tr>
	<tr class='bgcol1 bold col1 ht center'>
		<td>순번</td>
		<td>코드</td>
		<td>카테고리명</td>
		<td>등록일</td>
		<td><img src='<?=$g4[admin_path]?>/img/icon_insert.gif' title='1차 카테고리 생성' style="cursor:pointer" onclick="location.href='./category_form.php';"></td>
	</tr>
	<tr><td colspan="<?=$colspan?>" class="line2"></td></tr>
	<?
	$NO = 1;
	while($LIST = mysql_fetch_array($RESULT))
	{
		if($searchCate!="")
		{
			$strFind=mysql_num_rows(mysql_query("select * from g4_category where c_depth='1' and c_pcode='$LIST[c_code]' and c_name like '%$searchCate%'"));
		}
	?>
	<tr align="center" bgcolor="#EFEFEF" onmouseover="this.style.background='#CCFFFF'" onmouseout="this.style.background='#EFEFEF'">
		<td onclick="ShowLayer('<?=$LIST[c_code]?>');" style="cursor:pointer"><?=$NO?></td>
		<td align="left" onclick="ShowLayer('<?=$LIST[c_code]?>');" style="cursor:pointer"><?=$LIST[c_code]?></td>
		<td align="left" onclick="ShowLayer('<?=$LIST[c_code]?>');" style="cursor:pointer;<?if($strFind){echo("background:#FF9900");}?>">(<?=$LIST[c_sort]?>)<?=$LIST[c_name]?></td>
		<td onclick="ShowLayer('<?=$LIST[c_code]?>');" style="cursor:pointer"><?=date("Y-m-d",strtotime($LIST[c_regday]))?></td>
		<td align="right">
		<img src='<?=$g4[admin_path]?>/img/icon_insert.gif' title='2차 카테고리 생성' style="cursor:pointer" onclick="location.href='./category_form.php?c_code=<?=$LIST['c_code']?>&c_depth=<?=$LIST[c_depth]?>';">
		<img src='<?=$g4[admin_path]?>/img/icon_modify.gif' title='수정' style="cursor:pointer" onclick="location.href='./category_form.php?w=u&IDX=<?=$LIST[idx]?>';">
		<img src='<?=$g4[admin_path]?>/img/icon_delete.gif' title='삭제' style="cursor:pointer" onclick="if(confirm('1차 카테고리를 삭제하시면 하위 카테고리도 삭제됩니다.\n\n                   삭제하시겠습니까?')){location.href='./category_update.php?w=d&c_code=<?=$LIST[c_code]?>';}">
		</td>
	</tr>
	<tr>
		<td colspan="<?=$colspan?>" align="right">
			<DIV ID="<?=$LIST[c_code]?>" style="display:none;width:100%">
			<?
			$QUERY2 = "select * from g4_category where c_depth='1' and c_pcode='$LIST[c_code]' order by c_sort ASC, c_regday ASC";
			$RESULT2 = mysql_query($QUERY2);
			?>
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<colgroup width="50">
				<colgroup width="120">
				<colgroup width="">
				<colgroup width="100">
				<colgroup width="100">
				<?
				while($LIST2 = mysql_fetch_array($RESULT2))
				{
				?>
				<tr align="center" onmouseover="this.style.background='#CCFFCC'" onmouseout="this.style.background='#FFFFFF'">
					<td></td>
					<td align="left" style="padding-left:10px;color:#CCCCCC"><?=$LIST2[c_code]?></td>
					<td align="left" style="padding-left:10px"><?=$LIST2[c_name]?></td>
					<td style="padding-right:15px"><?=date("Y-m-d",strtotime($LIST2[c_regday]))?></td>
					<td align="right">
					<img src='<?=$g4[admin_path]?>/img/icon_modify.gif' title='수정' style="cursor:pointer" onclick="location.href='./category_form.php?w=u&IDX=<?=$LIST2[idx]?>';">
					<img src='<?=$g4[admin_path]?>/img/icon_delete.gif' title='삭제' style="cursor:pointer" onclick="if(confirm('삭제하시겠습니까?')){location.href='./category_update.php?w=d&c_code=<?=$LIST2[c_code]?>';}">
					</td>
				</tr>
				<?
				}
				?>
			</table>
			</DIV>
		</td>
	</tr>
	<tr><td colspan="<?=$colspan?>" class="line2"></td></tr>
	<?
		$NO++;
	}
	?>
</table>
<script>
function ShowLayer(LAYER)
{
	var Display = document.all(LAYER).style.display;
	if(Display == "none")
	{
		document.all(LAYER).style.display = "inline";
	}
	else
	{
		document.all(LAYER).style.display = "none";
	}
}
</script>
<?
include_once ("./admin.tail.php");
?>